package com.ruoyi.web.controller.app.im.app.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.im.domain.UserGroupGrouping;
import com.ruoyi.im.domain.UserGroupList;
import com.ruoyi.sj.domain.vo.DynamicDetails;
import com.ruoyi.web.controller.app.im.app.service.AppUserService;
import com.ruoyi.web.core.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "用户模块", position = 1)
@RestController
@RequestMapping("/app/userinfo")
public class AppUserController extends BaseController {

    @Autowired
    private AppUserService appUserService;

    /**
     * 查询用户好友分组信息
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupList")
    @ApiOperation(notes = "findUserGroupList", position = 1, value = "查询用户好友分组信息", response = UserGroupList.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserGroupList(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserGroupList(params.get("userId")));
    }


    /**
     * 搜索好友
     *
     * @param params
     * @return
     */
    @PostMapping("findUserByNickNameList")
    @ApiOperation(notes = "findUserByNickNameList", position = 2, value = "搜索好友")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", value = "用户昵称", required = true, paramType = "query", dataType = "string")
    })
    public XResult findUserByNickNameList(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("搜索成功", appUserService.findUserByNickNameList(params.get("search")));
    }

    /**
     * 搜索群
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupListByLickName")
    @ApiOperation(notes = "findUserGroupListByLickName", position = 3, value = "搜索群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "群类型（1.通讯录，2.闺蜜圈）", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupname", value = "群名称", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "longitude", value = "当前经度", required = false, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "latitude", value = "当前纬度", required = false, paramType = "query", dataType = "string"),
    })
    public XResult findUserGroupListByLickName(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("搜索成功", appUserService.findUserGroupListByLickName(params.get("type"), params.get("groupname"), params.get("longitude"), params.get("latitude")));
    }

    /**
     * 发送好友申请
     *
     * @param params
     * @return
     */
    @PostMapping("sendingFriendsApplication")
    @ApiOperation(notes = "sendingFriendsApplication", position = 4, value = "发送好友申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "validationMessage", value = "验证信息", required = false, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "applicantId", value = "申请人id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "remarks", value = "备注", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "分组id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "claimantId", value = "被申请人id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult sendingFriendsApplication(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        int count = appUserService.sendingFriendsApplication(params);
        if (count > 0) {
            return new XResult("申请成功", count);
        } else {
            return new XResult("申请失败", count);
        }
    }

    /**
     * 好友申请确认
     *
     * @param params
     * @return
     */
    @PostMapping("friendsConfirmation")
    @ApiOperation(notes = "friendsConfirmation", position = 5, value = "好友申请确认")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "validationMessage", value = "验证信息", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "applicantId", value = "申请人id", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "remarks", value = "备注", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "groupId", value = "分组id", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "groupIdTo", value = "申请人分组id", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "claimantId", value = "被申请人id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "friendId", value = "申请列表数据id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "确认状态(1：同意，2：拒绝，3：忽略)", required = true, paramType = "query", dataType = "string"),
    })
    public XResult friendsConfirmation(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        int count = appUserService.friendsConfirmation(params);
        if (count > 0) {
            return new XResult("添加成功", count);
        } else {
            return new XResult("添加失败", count);
        }
    }

    /**
     * 发送群申请
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupListByUserId")
    @ApiOperation(notes = "findUserGroupListByUserId", position = 6, value = "发送群申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "validationMessage", value = "验证信息", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "applicantId", value = "申请人id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "remarks", value = "备注", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupsId", value = "申请加入群id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserGroupListByUserId(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("发送成功", appUserService.findUserGroupListByUserId(params));
    }

    /**
     * 群确认
     *
     * @param params
     * @return
     */
    @PostMapping("groupConfirmation")
    @ApiOperation(notes = "groupConfirmation", position = 7, value = "群确认(弃用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applicantId", value = "申请人id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupsId", value = "被申请群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "确认状态(1：同意，2：拒绝，3：忽略)", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "friendId", value = "申请列表数据id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult groupConfirmation(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        int count = appUserService.groupConfirmation(params);
        if (count > 0) {
            return new XResult("添加成功", count);
        } else {
            return new XResult("添加失败", count);
        }
    }

    /**
     * 查询用户被申请加为好友申请列表
     *
     * @param params
     * @return
     */
    @PostMapping("findFriendApplicationListByclaimantId")
    @ApiOperation(notes = "findFriendApplicationListByclaimantId", position = 8, value = "查询用户被申请加为好友申请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
//            @ApiImplicitParam(name = "type", value = "查询消息类型（1：好友申请2：群申请）", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findFriendApplicationListByclaimantId(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("获取成功", appUserService.findFriendApplicationListByclaimantId(params.get("userId") + "", "1"));
    }

    /**
     * 查询自己的分组列表信息
     *
     * @param params
     * @return
     */
    @PostMapping("findGroupingListByUserId")
    @ApiOperation(notes = "findGroupingListByUserId", position = 9, value = "查询自己的分组列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findGroupingListByUserId(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("获取成功", appUserService.findGroupingListByUserId(params.get("userId") + ""));
    }


    /**
     * 用户删除分组信息
     *
     * @param params
     * @return
     */
    @PostMapping("deleteGroupingById")
    @ApiOperation(notes = "deleteGroupingById", position = 10, value = "用户删除分组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult deleteGroupingById(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("删除成功", appUserService.deleteGroupingById(params.get("id") + ""));
    }

    /**
     * 用户添加分组
     *
     * @param params
     * @return
     */
    @PostMapping("createGrouping")
    @ApiOperation(notes = "createGrouping", position = 11, value = "用户添加分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "分组名称", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "分组类型（1：好友分组2：群分组）", required = true, paramType = "query", dataType = "string"),
    })
    public XResult createGrouping(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("创建成功", appUserService.createGrouping(params));
    }

    /**
     * 查询用户群分组信息
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupGroupingList")
    @ApiOperation(notes = "findUserGroupGroupingList", position = 12, value = "查询用户群分组信息", response = UserGroupGrouping.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserGroupGroupingList(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserGroupGroupingList(params.get("userId")));
    }

    /**
     * 查看群详情
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupListBygroupId")
    @ApiOperation(notes = "findUserGroupListBygroupId", position = 13, value = "查看群详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserGroupListBygroupId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserGroupListBygroupId(params.get("groupId"), params.get("userId")));
    }

    /**
     * 查询群好友详情
     *
     * @param params
     * @return
     */
    @PostMapping("findUserByUserId")
    @ApiOperation(notes = "findUserByUserId", position = 14, value = "查询群好友详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "所在群id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserByUserId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserByUserId(params.get("userId"), params.get("groupId")));
    }

    /**
     * 更新加群设置
     *
     * @param params
     * @return
     */
    @PostMapping("updateUserGroupSetting")
    @ApiOperation(notes = "updateUserGroupSetting", position = 15, value = "更新加群设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "加群设置类型（1：允许任何人加群2、需要身份验证3、不允许任何人加群）", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateUserGroupSetting(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.updateUserGroupSetting(params));
    }

    /**
     * 群昵称设置
     *
     * @param params
     * @return
     */
    @PostMapping("setGroupNickName")
    @ApiOperation(notes = "setGroupNickName", position = 16, value = "群昵称设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "nickname", value = "群昵称", required = true, paramType = "query", dataType = "string"),
    })
    public XResult setGroupNickName(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.setGroupNickName(params));
    }

    /**
     * 好友拉入黑名单
     *
     * @param params
     * @return
     */
    @PostMapping("createBlacklist")
    @ApiOperation(notes = "createBlacklist", position = 17, value = "好友拉入黑名单")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "groupId", value = "分组id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pullerUserId", value = "被拉入黑名单用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult createBlacklist(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("拉入黑名单成功", appUserService.createBlacklist(params));
    }

    /**
     * 群内用户禁言
     *
     * @param params
     * @return
     */
    @PostMapping("createAnExcuse")
    @ApiOperation(notes = "createAnExcuse", position = 18, value = "群内用户禁言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "excuseTimeLen", value = "禁言时长", required = true, paramType = "query", dataType = "string"),
    })
    public XResult createAnExcuse(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("禁言成功", appUserService.createAnExcuse(params));
    }

    /**
     * 根据用户id查询用户信息
     *
     * @param params
     * @return
     */
    @PostMapping("findUserById")
    @ApiOperation(notes = "findUserById", position = 19, value = "根据用户id查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findUserById(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserById(params.get("userId")));
    }

    /**
     * 用户好友设置备注名
     *
     * @param params
     * @return
     */
    @PostMapping("updateFriendsMemoName")
    @ApiOperation(notes = "updateFriendsMemoName", position = 20, value = "用户好友设置备注名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pullerUserId", value = "好友id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "memoName", value = "备注名", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateFriendsMemoName(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.updateFriendsMemoName(params));
    }


    /**
     * 根据用户id查询自己拉入黑名单好友数据
     *
     * @param params
     * @return
     */
    @PostMapping("selectBlacklistListByUserId")
    @ApiOperation(notes = "selectBlacklistListByUserId", position = 21, value = "根据用户id查询自己拉入黑名单好友数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult selectBlacklistListByUserId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.selectBlacklistListByUserId(params));
    }

    /**
     * 删除黑名单好友信息
     *
     * @param id
     * @return
     */
    @PostMapping("deleteBlacklistUser")
    @ApiOperation(notes = "deleteBlacklistUser", position = 22, value = "删除黑名单好友信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "黑名单id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult deleteBlacklistUser(@RequestParam @ApiIgnore String id, @ApiIgnore HttpServletRequest request) {
        return new XResult("删除成功", appUserService.deleteBlacklistUser(id));
    }

    /**
     * 根据用户id及群id查询查询用户群分组信息进行分组的更新
     *
     * @param params
     * @return
     */
    @PostMapping("selectGroupGroupingDetailsByGroupIdAndUserId")
    @ApiOperation(notes = "selectGroupGroupingDetailsByGroupIdAndUserId", position = 23, value = "用户群分组更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "所在群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupingId", value = "新的分组id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult selectGroupGroupingDetailsByGroupIdAndUserId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("更新分组成功", appUserService.selectGroupGroupingDetailsByGroupIdAndUserId(params));
    }

    /**
     * 用户退群
     *
     * @param params
     * @return
     */
    @PostMapping("userRetreatGroup")
    @ApiOperation(notes = "userRetreatGroup", position = 24, value = "用户退群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "所在群id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult userRetreatGroup(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("退群成功", appUserService.userRetreatGroup(params));
    }

    /**
     * 用户解散群
     *
     * @param params
     * @return
     */
    @PostMapping("disbandedGroup")
    @ApiOperation(notes = "disbandedGroup", position = 25, value = "用户解散群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "用户解散群id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult disbandedGroup(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("解散群成功", appUserService.disbandedGroup(params));
    }

    /**
     * 群主修改群名称
     *
     * @param params
     * @return
     */
    @PostMapping("updateUserGroup")
    @ApiOperation(notes = "updateUserGroup", position = 26, value = "群主修改群名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupName", value = "修改的群名称", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateUserGroup(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("修改成功", appUserService.updateUserGroup(params));
    }


    /**
     * 修改群消息勿扰状态
     *
     * @param params
     * @return
     */
    @PostMapping("updateGroupDisturb")
    @ApiOperation(notes = "updateGroupDisturb", position = 27, value = "修改群消息勿扰状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "所在群id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "disturb", value = "消息勿扰状态（1：开启2：关闭）", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateGroupDisturb(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.updateGroupDisturb(params));
    }

    /**
     * 用户修改分组名称
     *
     * @param params
     * @return
     */
    @PostMapping("updateGroupingName")
    @ApiOperation(notes = "updateGroupingName", position = 28, value = "用户修改分组名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分组id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "分组名称", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateGroupingName(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.updateGroupingName(params));
    }

    /**
     * 群主修改群介绍
     *
     * @param params
     * @return
     */
    @PostMapping("updateUserGroupGroupRemarks")
    @ApiOperation(notes = "updateUserGroupGroupRemarks", position = 29, value = "群主修改群介绍")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "qunid", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "introduce", value = "群介绍", required = true, paramType = "query", dataType = "string"),
    })
    public XResult updateUserGroupGroupRemarks(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("设置成功", appUserService.updateUserGroupGroupRemarks(params));
    }

    /**
     * 创建群聊
     *
     * @param params
     * @return
     */
    @PostMapping("createUserGroup")
    @ApiOperation(notes = "createUserGroup", position = 30, value = "创建群聊")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "群类型（1.通讯录，2.闺蜜圈）", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "longitude", value = "建群经度", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "latitude", value = "建群纬度", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "distance", value = "允许搜索距离", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupName", value = "群名称", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupLogo", value = "群头像", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupRemarks", value = "群介绍", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "userId", value = "创建群的用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupPlace", value = "群地点", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "cost", value = "进群费用", required = false, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "limit", value = "群成员上限", required = false, paramType = "query", dataType = "string")
    })
    public XResult createUserGroup(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        String count = appUserService.createUserGroup(params);
        if (StringUtils.isNotBlank(count)) {
            return new XResult("创建成功", count);
        } else {
            return new XResult("创建失败");
        }
    }

    /**
     * 添加是验证是否已经是好友
     *
     * @param params
     * @return
     */
    @PostMapping("verificationUserFriends")
    @ApiOperation(notes = "verificationUserFriends", position = 31, value = "添加是验证是否已经是好友")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pullerUserId", value = "加好友的id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult verificationUserFriends(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("验证成功", appUserService.verificationUserFriends(params));
    }

    /**
     * 删除好友
     *
     * @param params
     * @return
     */
    @PostMapping("deleteUserFriends")
    @ApiOperation(notes = "deleteUserFriends", position = 32, value = "删除好友")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pullerUserId", value = "好友id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult deleteUserFriends(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("删除成功", appUserService.deleteUserFriends(params));
    }

    /**
     * 群主邀请好友进群
     *
     * @param params
     * @return
     */
    @PostMapping("invitations")
    @ApiOperation(notes = "invitations", position = 33, value = "群主邀请好友进群")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applicantId", value = "主动邀请用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "claimantId", value = "被邀请入群用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupsId", value = "邀请好友进群id", required = true, paramType = "query", dataType = "string"),

    })
    public XResult invitations(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        int count = appUserService.invitations(params);
        if (count > 0) {
            return new XResult("邀请成功", count);
        } else {
            return new XResult("邀请失败", count);
        }
    }

    /**
     * 查询群验证通知信息
     *
     * @param params
     * @return
     */
    @PostMapping("findUserGroupListByGroupUserId")
    @ApiOperation(notes = "findUserGroupListByGroupUserId", position = 34, value = "查询群验证通知信息（弃用）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),

    })
    public XResult findUserGroupListByGroupUserId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findUserGroupListByGroupUserId(params.get("userId")));
    }

    /**
     * 查询自己被其他用户邀请进群需要自己同意的验证信息
     *
     * @param params
     * @return
     */
    @PostMapping("findClaimantUserByClaimantId")
    @ApiOperation(notes = "findClaimantUserByClaimantId", position = 35, value = "查询自己被其他用户邀请进群需要自己同意的验证信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),

    })
    public XResult findClaimantUserByClaimantId(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("查询成功", appUserService.findClaimantUserByClaimantId(params.get("userId")));
    }

    /**
     * 邀请用户进群确认（受邀请方确认）
     *
     * @param params
     * @return
     */
    @PostMapping("userConfirmation")
    @ApiOperation(notes = "userConfirmation", position = 36, value = "邀请用户进群确认（受邀请方确认）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "friendId", value = "申请数据的id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "确认状态(1：同意，2：拒绝，3：忽略)", required = true, paramType = "query", dataType = "string"),

    })
    public XResult userConfirmation(@RequestParam @ApiIgnore Map<String, Object> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("确认成功", appUserService.userConfirmation(params));
    }

    /**
     * 保存闺蜜
     *
     * @return
     */
    @PostMapping("saveConfidante")
    @ApiOperation(notes = "saveConfidante", position = 36, value = "保存闺蜜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "confidanteId", value = "闺蜜ID", required = true, paramType = "query", dataType = "string"),

    })
    public XResult saveConfidante(String userId, String confidanteId) {
        return new XResult("保存成功", appUserService.insertConfidante(userId, confidanteId));
    }

    /**
     * 删除闺蜜
     *
     * @return
     */
    @PostMapping("deleteConfidante")
    @ApiOperation(notes = "deleteConfidante", position = 36, value = "删除闺蜜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "confidanteId", value = "闺蜜ID", required = true, paramType = "query", dataType = "string"),

    })
    public XResult deleteConfidante(String userId, String confidanteId) {
        return new XResult("删除成功", appUserService.deleteConfidante(userId, confidanteId));
    }

    /**
     * 查询闺蜜
     *
     * @return
     */
    @PostMapping("selectConfidante")
    @ApiOperation(notes = "selectConfidante", position = 36, value = "查询闺蜜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "string")
    })
    public XResult selectConfidante(String userId) {
        startPage();
        List<Map<String, Object>> maps = appUserService.selectConfidante(userId);
        TableDataInfo dataTable = getDataTable(maps);
        return new XResult("查询成功", dataTable);
    }

    /**
     * 查询群聊里没有的闺蜜
     *
     * @return
     */
    @PostMapping("selectNotJoinGroupConfidante")
    @ApiOperation(notes = "selectNotJoinGroupConfidante", position = 36, value = "查询群聊里没有的闺蜜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "群ID", required = true, paramType = "query", dataType = "string")
    })
    public XResult selectNotJoinGroupConfidante(String userId, String groupId) {
        startPage();
        List<Map<String, Object>> maps = appUserService.selectNotJoinGroupConfidante(userId, groupId);
        TableDataInfo dataTable = getDataTable(maps);
        return new XResult("查询成功", dataTable);
    }

    /**
     * 查询群聊里已有的闺蜜
     *
     * @return
     */
    @PostMapping("selectJoinGroupConfidante")
    @ApiOperation(notes = "selectJoinGroupConfidante", position = 36, value = "查询群聊里已有的闺蜜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "groupId", value = "群ID", required = true, paramType = "query", dataType = "string")
    })
    public XResult selectJoinGroupConfidante(String userId, String groupId) {
        startPage();
        List<Map<String, Object>> maps = appUserService.selectJoinGroupConfidante(userId, groupId);
        TableDataInfo dataTable = getDataTable(maps);
        return new XResult("查询成功", dataTable);
    }

    /**
     * 通过id删除验证信息
     *
     * @param id
     * @return
     */
    @PostMapping("deleteMessageById")
    @ApiOperation(notes = "deleteMessageById", position = 37, value = "删除验证信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "信息id", required = true, paramType = "query", dataType = "string")
    })
    public XResult deleteMessageById(Long id) {

        return new XResult("查询成功", appUserService.deleteMessageById(id));
    }

}


